package com.yanfan.ccapicode.mangaer.impl;


import com.yanfan.ccapicode.bean.message.DelayMessage;
import com.yanfan.ccapicode.mangaer.DelayMessageManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class DelayMessageManagerImpl implements DelayMessageManager {

    private static final Logger log = LoggerFactory.getLogger(DelayMessageManager.class);

//    @Autowired(required = false)
//    private RabbitTemplate rabbitTemplate;

    /**
     * 发布延时消息
     * @param delayMessage 延时消息
     * @param delay 延时时间 单位毫秒
     * @return
     */
    @Override
    public void pushMessage(DelayMessage delayMessage, int delay) {
        if (delayMessage == null){
            return;
        }
//        String msgId = UUID.randomUUID().toString();
//        MessageProperties messageProperties = new MessageProperties();
//        messageProperties.setMessageId(msgId);
//        messageProperties.setCorrelationId(msgId);
//        messageProperties.setDelay(delay);
//        Message message = new Message(JSONObject.toJSONString(delayMessage).getBytes(), messageProperties);
//        CorrelationData correlationData = new CorrelationData();
//        correlationData.setId(msgId);
//        log.info("消息ID:{}", msgId);
//        log.info("内容：{}", JSONObject.toJSONString(delayMessage));
//        rabbitTemplate.convertAndSend(DelayedQueueConfig.EX_DELAYED, DelayedQueueConfig.R_DELAYED, message, correlationData);
    }
}
